/**
 * ============================================================================
 * alert
 * ============================================================================
 */
var alertUI = (function(){

	var timer;
	var $alertTips = $('#alertTips');
	var $alertTipsInner = $('#alertTipsInner');

	function init(text, time) {
		var time = time || 1000;

		clearTimeout(timer);
		$alertTipsInner[0].innerHTML = text;
		$alertTips.show();
		timer = setTimeout(function(){
			$alertTips.hide();
		},time);

	}

	return {
		init: init
	}


}());

/**
 * ============================================================================
 * toggle
 * ============================================================================
 */
var toggle = (function($){

	function toggleFun($self, other) {
		var show = false;
		var $parent = $self.parent();

		if (!$parent.hasClass("active")) {
			show = true;
		}

		$(other).removeClass("active");

		if (show) {
			$parent.addClass("active");
		}
	}

	$("body").on("click", "[data-toggle='toggle']", function(e){
		e.preventDefault();

		var $self = $(this);
		var other = $self.attr("data-toggle-box");

		toggleFun($self, other);	
	});

	return {
		toggleFun: toggleFun
	};

}(Zepto));


/**
 * ============================================================================
 * 获取数据
 * ============================================================================
 */
var modelModule = (function(){

	var dataUrl = '../common/CommonCtrl/getOverseaSafeInfoById';

	function dataCallback(json, $tmpl, $appedEL, fn) {

 		$appedEL[0].innerHTML = doT.compile($tmpl[0].innerHTML)(json);

 		fn && fn();
 	}

 	function getData() {
 		var data = {
 				'id': wxUtils.getParamsByUrl('id')
 		};
 		$.ajax({
 			type: 'POST',
 			url: dataUrl,
 			contentType : 'application/json',
 			data : JSON.stringify(data),
 			dataType : 'json',
 			success: function(json) {
 				if (json.resultCode == '200') {
 					var result=json.result;
 					//产品名称
 					$('#name').html(result.name);
 					//产品特色
 					$('#proFeatureTxt').html(result.proFeatureTxt);
 					
 					var json = {
			 			title1: '产品保障详情',
			 			content1: result.proEnsureTxt,
			 			title2: '产品要素',
			 			content2: {
			 				c_title1: '产品类型：',
			 				c_content1:getDescByCode.getOprodType(result.prodType),
			 				c_title2: '供款年限：',
			 				c_content2: getDescByCode.getOcontributionsTime(result.contributionsTime),
							c_title3: '保障期限：',
			 				c_content3: result.insureTerm==null?'':result.insureTerm,
							c_title4: '投保年龄：',
			 				c_content4: getDescByCode.getOtbAge(result.tbAge),
							c_title5: '供款货币：',
			 				c_content5: getDescByCode.getOgkCoin(result.gkCoin),
							c_title6: '首期供款方式：',
			 				c_content6: getDescByCode.getOfirstGktype(result.firstGktype),
							c_title7: '免体检额度：',
			 				c_content7: result.noCheckLimit==null?'':result.noCheckLimit,
	 						c_title8: '冷静期：',
			 				c_content8: result.calmTerm==null?'':result.calmTerm,
	 						c_title9: '续期供款方式：',
			 				c_content9: result.againGktype==null?'':result.againGktype,
	 						c_title10: '预期分红收益：',
			 				c_content10: result.dividendGains==null?'':result.dividendGains,
	 						c_title11: '最低投保额：',
			 				c_content11: result.lowestCredit==null?'':result.lowestCredit
			 			},
			 			title3: '投保案例展示',
			 			content3: result.coverCaseTxt,
			 			title4: '投保流程',
			 			content4: result.coverFlowTxt,
			 		};
 					dataCallback(json, $('#panelListTmpl'), $('#panelList'));
 				} else {
 					alertUI.init('网络繁忙，请稍后再试');
 				}
 			},
 			error: function() {
 				alertUI.init('网络繁忙，请稍后再试');
 			}
 		});
 	}

 	function init() {
 		getData();
 		var json = {
	 			title1: '产品保障详情',
	 			content1: '',
	 			title2: '产品要素',
	 			content2: '',
	 			title3: '投保案例展示',
	 			content3: '',
	 			title4: '投保流程',
	 			content5: '',
	 		};
		dataCallback(json, $('#panelListTmpl'), $('#panelList'));
 	}

 	init();


}());

